Boolean and Sets

In this tutorial we shall discuss about Boolean and Sets. Topics we have discussed in previous tutorials:

  • Dictionaries
  • Functions of dictionaries
  • Tuples
  • Functions of tuples
  • Sets
  • Few important functions of sets

Boolean:

Boolean are the expression such as True, False. These are used to test the data whether it is correct or wrong. 

            E.g: If we type 1 == 1 as code, we know this value is correct and run the code we get True.

Boolean Eg1.png

E.g2 : If we type 1 == 5 as code, we know this value is correct and run the code we get False .

Boolean Eg2.png

This is the basic applications of Booleans. Now lets continue with some complicated data types in python.

and:

If we use this keyword between two conditions and two of the conditions are true then the value will be true or else for any other case it will be false. We also can use this between multiple conditions.

Boolean Eg4.png
Condition 1Condition 2Output
TrueTrueTrue
TrueFalseFalse
FalseTrueFalse
FalseFalseFalse

or:

If we use this keyword between two conditions and two of the conditions are true then value will be true or else for any other case it will be fasle. We also can use this between multiple conditions.

Boolean Eg5.png
Condition 1Condition 2Output
TrueTrueTrue
TrueFalseTrue
FalseTrueTrue
FalseFalseFalse

These are two important Booleans we will be using very regularly in data manipulation techniques.

Application of Boolean:

  • To check whether an item belongs to the list or not.                                                                                               
  •   To check we have to write: element in the list.
Application of Boolean.png
Comparision Operators.png

Decision Making in Python:

Checking a condition and making the correct decision ( here correct means given by programmer ) is known as decision making.

if statement:

This is a decision-making statement, where a condition is given to it and asked for a decision.

            Syntax:

Example.png
if condition.png

else statement:

This statement is used for only other than condition after if statement.

If else condition.png

elif statement :

This statement is used for multiple conditions other than if condition .

Flow Chart.jpg

If any query in this tutorial let us know in the comment section.

Topics we will cover in the next tutorial:

  • Iterations
  • For loops
  • While loops
  • Range
  • List comprehension

For more information visit the section of Data Science.

Spread knowledge

Leave a Comment

Your email address will not be published. Required fields are marked *